package com.quectel.cms;

import com.quectel.util.kit.Snowflake;
import org.apache.dubbo.common.constants.CommonConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"com.quectel"}) //需要扫描导入的包，必须加载scanBasePackages={"com.quectel"}
public class CmsApiServer {
    private static final Logger LOGGER = LoggerFactory.getLogger(CmsApiServer.class);

    public static void main(String[] args) {


        // 忽略docker0网卡防止在安装docker的机器上向注册中心产生错误的服务IP（会出现注册IP为172.17.0.1）
        System.setProperty(CommonConstants.DUBBO_NETWORK_IGNORED_INTERFACE, "docker0");
        // 在Dubbo内部优先使用jackson
        System.setProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME, "jackson");

        SpringApplication.run(CmsApiServer.class, args);

        //kill -9 不生效
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            Snowflake.free();
            LOGGER.info("Snowflake requested resources are released");
        }));

        LOGGER.info("The maximum memory that can be applied for in this project is:{}m", Runtime.getRuntime().maxMemory() / 1024 / 1024);
    }
}